<template>
	<view>
		<view class="headBar">
			<view class="date">
				<image src="/static/date2.png" mode="aspectFit"></image>
				<text class="num">{{date}}</text>
				<text class="day">日</text>
			</view>
			<view class="today">
				<view class="key" v-if="isShow" @click="isShow=false">今日收入(元) <text class="cuIcon-attention"></text></view>
				<view class="key" v-else @click="isShow=true">今日收入(元) <text class="cuIcon-attentionforbid"></text></view>
				<view>{{isShow?money.dayMoney:'***'}}</view>
			</view>
			<view class="min">
				<view>
					<view class="key">{{month}}月份收入(元)</view>
					<view>{{isShow?money.monthMoney:'***'}}</view>
				</view>
				<view>
					<view class="key">近七日收益(元)</view>
					<view>{{isShow?money.weekMoney:'***'}}</view>
				</view>
			</view>
			<view class="note" @click="scan">
				<view><text class="label">扫一扫</text>设备\订单扫码~</view>
				<view class="goto">
					<text class="cuIcon-scan"></text>
				</view>
			</view>
		</view>
		<view class="applys">
			<view class="title">常用应用</view>
			<view class="content">
				<block v-for="(item,index) in appList" :key="index">
					<view class="item" @click="$utils.toURL(item.url)" v-if="item.homeShow==1">
						<view class="img-bg">
							<image :src="httpDomain+item.iconImg" mode="aspectFit"></image>
						</view>
						<view class="txt">{{item.name}}</view>
					</view>
				</block>
	<!-- 			<view class="item" @click="$utils.toURL('/coupon/car/car')">
					<view class="img-bg">
						<image src="/static/ico/ico-device1.png" mode="aspectFit"></image>
					</view>
					<view class="txt">核销洗车券</view>
				</view> -->
			</view>
		</view>
		<view class="foot"><text class="ftxt">我也是有底线的</text></view>
		<view class="logs" v-if="phone=='15992323793'">
			<view class="item" v-for="(item,index) in logs" :key="index">{{item}}</view>
		</view>
	</view>
</template>

<script>
	const wx = require('@/js_sdk/jweixin.js'); 
	export default {
		data() {
			return {
				logs:[],
				phone:null,
		
				httpDomain:'',
				date:0,
				month:0,
				monthStr:['一','二','三','四','五','六','七','八','九','十','十一','十二'],
				money:{},
				isShow:true,
				appList:[
					// {ico:'ico-device1',txt:'设备概览',path:'/device/cdcz/overview'},
					// {ico:'ico-cangku',txt:'设备仓库',path:'/device/cdcz/warehouse'},
					// {ico:'ico-dian1',txt:'已投设备',path:'/device/cdcz/list'},
					// {ico:'ico-order2',txt:'充电订单',path:'/order/cdcz/list'},
					// {ico:'ico-location',txt:'充电网点',path:'/place/general/place'},
					
					// {ico:'ico-yue',txt:'商家余额',path:'/account/cash/cash'},
					// {ico:'ico-zhang',txt:'账单明细',path:'/account/detail/list'},
					// {ico:'ico-bili',txt:'分成设置',path:'/account/divide/index'},
					// {ico:'ico-staff',txt:'员工管理',path:'/other/staff/list'},
					
					// {ico:'ico-location',txt:'推荐网点',path:'/referrer/place/place'},
					// {ico:'ico-staff1',txt:'推荐代理',path:'/referrer/agent/list'},
						
					// {ico:'ico-gaojing',txt:'异常处理',path:'/tool/unusual/dingbell'},
				]
			}
		},
		onShow() {
			const date = new Date();
			this.date = date.getDate();
			this.month = this.monthStr[date.getMonth()]
			this.appList = [
				// {id:100,iconImg:'/oem/judao/ico-device.png',name:'设备概览',url:'/device/index',homeShow:1},
			];
			
			console.log(this.$store.getters.GET_userInfo);
			
			const api = this.$request;
			//首页金额信息
			api.post(api.url.myIndexInfo,{},res=>{
				this.money = {
					dayMoney:res.body.dayMoney,
					monthMoney:res.body.monthMoney,
					weekMoney:res.body.weekMoney
				}
			})
			//功能项目信息
			api.post(api.url.myModelList,{},res=>{
				if(res.code==200){
					const items = res.body.items || [];
					items.push({id:101,iconImg:'/oem/judao/ico-more.png',name:'更多',url:'/index/more',homeShow:1})
					this.appList = this.appList.concat(items)
				}else{
					const arr = [{id:101,iconImg:'/oem/judao/ico-more.png',name:'更多',url:'/index/more',homeShow:1}];
					this.appList = this.appList.concat(arr)
				}
			})
		},
		onLoad(option) {
			this.jssdk();
		},
		methods: {
			// btnTest(){
			// 	const api = this.$request;
			// 	api.post(api.url.commQRcode,{
			// 		// qrcode:'https://develop.busi.judaozhineng.cn/dev/cdcz/860721064801624'
			// 		// qrcode:'https://develop.busi.judaozhineng.cn/dev/cdb/CDBV1A100F010001'
			// 		// qrcode:'CODE_128,M3CBZ7HD6170070'
			// 		qrcode:'https://develop.busi.judaozhineng.cn/bxscn/shop/order/231694762320022'
			// 		// qrcode:'https://develop.busi.judaozhineng.cn/place/physical_store/169'
			// 	},res=>{
			// 		console.log("=======扫码")
			// 		console.log(res)
			// 	})
			// },
			jssdk(){
				let url = location.href.split('#')[0];
				this.logs.push({url:url});    //日志
				const api = this.$request;
				const self = this;
				api.post(api.url.wxSDK,{
					appId:this.$store.getters.GET_AppId,
					url:url
				},res=>{
					console.log(res)
					self.logs.push({config:'--------------------'});
					self.logs.push(res);    //日志
					if(res.code==200){
						const data = res.body;
						wx.config({
						  debug: false,
						  appId: data.config.appId,        // 必填，公众号的唯一标识
						  timestamp: data.config.timestamp,// 必填，生成签名的时间戳
						  nonceStr: data.config.nonceStr,  // 必填，生成签名的随机串
						  signature: data.config.signature,// 必填，签名
						  jsApiList: ['scanQRCode']        // 必填，需要使用的JS接口列表
						});
						wx.error((err)=>{
							self.logs.push({wxError:'--------------------'});
							self.logs.push(err);    //日志
						})
					}else{
						uni.showToast({
							title:res.msg,
							icon:'none'
						})
					}
				})
			},
			scan(){
				console.log("scanQRcode")
				const self = this;
				wx.ready(()=>{
					wx.scanQRCode({
						needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
						scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
						success: function (res) {
							self.logs.push({wxScan:'--------------------'});
							self.logs.push(res);    //日志
							console.log(res.resultStr);
							const arr = res.resultStr.split('/'); 
							if(/^(https:\/\/).+\/\w+\/\w+$/.test(res.resultStr)){
								self.logs.push({k3:arr[3]});
								self.logs.push({k4:arr[4]});
								if(arr[4].toUpperCase() =='CDB'){
									self.$utils.toURL('/device/cdb/warehouse?dev='+arr[5])
								}else if(arr[4].toUpperCase() =='CDCZ'){
									self.$utils.toURL('/device/cdcz/warehouse?dev='+arr[5])
								}else if(arr[3].toUpperCase() == 'BXSCN'){
									self.$utils.toURL('/cndc/order/detail?tradeNo='+arr[6])
								}else{
									uni.showModal({
										title:"错误二维码",
										content:'请扫居道二维码',
										showCancel:false
									})
								}
							}else if(arr[0]&&arr[0].split(',').length == 2){
								self.logs.push({bxscn:arr[0].split(',')[1]});
								self.$utils.toURL('/cndc/device/detail?id='+arr.pop().split(',').pop())
							}else{
								uni.showModal({
									title:"错误二维码",
									content:'请扫正确的二维码',
									showCancel:false
								})
							}
						}
					})
				})
			},
		}
	}
</script>

<style lang="less">
	.logs{
		padding: 0 20rpx 100rpx;
		.item{
			margin-bottom: 20rpx;
			color: #999;
		}
	}
	.headBar{
		width: 100%;
		height: 480rpx;
		padding-top: 100rpx;
		background: linear-gradient(160deg,#fa9454,#e65332);
		color: #fff4e7;
		text-align: center;
		font-size: 52rpx;
		position: relative;
		.date{
			position: absolute;
			top: 20rpx;
			right: 20rpx;
			color: #6e6e96;
			image{
				width: 100rpx;
				height: 100rpx;
			}
			.num{
				font-size: 40rpx;
				position: absolute;
				bottom: 24rpx;
				left: 50%;
				transform: translateX(-60%);
			}
			.day{
				font-size: 16rpx;
				position: absolute;
				bottom: 30rpx;
				right: 16rpx;
			}
		}
		.key{
			font-size: 24rpx;
			margin-bottom: 20rpx;
		}
		.today .key text{
			margin-left: 20rpx;
		}
		.min{
			margin-top: 50rpx;
			display: flex;
			justify-content: space-around;
			align-items: flex-start;
		}
		.note{
			width: 90%;
			height: 100rpx;
			border-radius: 20rpx;
			background-color: white;
			color: #333333;
			font-size: 28rpx;
			padding: 0 40rpx;
			position: absolute;
			bottom: -50rpx;
			left: 50%;
			transform: translateX(-50%);
			display: flex;
			justify-content: space-between;
			align-items: center;
			box-shadow: 0 6rpx 10rpx #e0e0e0;
			view{
				display: flex;
				justify-content: space-between;
				align-items: center;
			}
			.label{
				display: block;
				color: #fa9454;
				border: 1rpx solid #fa9454;
				padding: 6rpx 14rpx;
				font-size: 20rpx;
				margin-right: 20rpx;
				font-weight: 600;
			}
			.goto{
				color: #fa9454;
				font-size: 24rpx;
			}
		}
	}
	.applys{
		width: 90%;
		background-color: white;
		margin: 70rpx auto 0;
		padding: 20rpx;
		border-radius: 20rpx;
		box-shadow: 0 0 10rpx #e0e0e0;
		.title{
			font-weight: 600;
		}
		.content{
			display: flex;
			justify-content: flex-start;
			align-items: flex-start;
			flex-wrap: wrap;
			.item{
				margin-top: 40rpx;
				width: 25%;
				text-align: center;
				color: #676767;
				font-size: 24rpx;
				.img-bg{
					width: 68rpx;
					height: 68rpx;
					margin: 0 auto 10rpx;
					border-radius: 50%;
					background-color: #fff6e7;
					display: flex;
					justify-content: center;
					align-items: center;
					image{
						width: 48rpx;
						height: 48rpx;
					}
				}
			}
		}
	}
</style>
